package org.gruposp2p.dnie.service.jpa;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.gruposp2p.dnie.model.DNIeDocumentToSignOption;
import org.gruposp2p.dnie.model.DNIeSignedDocumentOptionSelected;
import org.gruposp2p.dnie.service.DNIeSignedDocumentOptionSelectedDAO;
import org.springframework.stereotype.Repository;

/**
 *
 * @author jj
 */
@Repository("signedDocumentOptionSelectedDao")
public class JpaDNIeSignedDocumentOptionSelectedDAO
        implements DNIeSignedDocumentOptionSelectedDAO{

     private EntityManager entityManager;

    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) {
            this.entityManager = entityManager;
    }

    public DNIeSignedDocumentOptionSelected findById(Integer id) {
        return entityManager.find(DNIeSignedDocumentOptionSelected.class, id);
    }

    public DNIeSignedDocumentOptionSelected save(DNIeSignedDocumentOptionSelected entity) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean delete(Integer documentId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getNumberByDocumentToSignOption(DNIeDocumentToSignOption dnieDocumentToSignOptionId) {
        Query query =entityManager.createQuery(
                "SELECT COUNT(o.id) FROM DNIeSignedDocumentOptionSelected o WHERE o.dnieDocumentToSignOptionId = :dnieDocumentToSignOptionId");
        query.setParameter("dnieDocumentToSignOptionId", dnieDocumentToSignOptionId);
        Number countResult = (Number) query.getSingleResult();
        return countResult.intValue();
    }

}
